﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace WL_WinForm
{
    public partial class FrmMain : Form
    {
        public static bool startForm = false;
        private FrmMainTool maintool = new FrmMainTool();
        public static FrmMain frmMain = null;
        public FrmMain()
        {
            InitializeComponent();

            frmMain = this;
            maintool.Show(this.dockPanel1, DockState.DockLeft);
        }

        private void dockPanel1_ActiveContentChanged(object sender, EventArgs e)
        {
            
        }

        private DockContent FindDocument(string text)
        {
            if (dockPanel1.DocumentStyle == DocumentStyle.SystemMdi)
            {
                foreach (Form form in MdiChildren)
                {
                    if (form.Text == text)
                    {
                        return form as DockContent;
                    }
                }

                return null;
            }
            else
            {
                foreach (DockContent content in dockPanel1.Documents)
                {
                    if (content.DockHandler.TabText == text)
                    {
                        return content;
                    }
                }

                return null;
            }
        }

        public DockContent ShowContent(string caption, Type formType)
        {
            DockContent frm = FindDocument(caption);
            if (frm == null)
            {
                frm = Activator.CreateInstance(formType) as DockContent;
                frm.DockHandler.TabText = caption;
                //frm = ChildWinManagement.LoadMdiForm(formType) as DockContent;
            }

            frm.Show(this.dockPanel1);
            frm.BringToFront();
            return frm;
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }
    }
}
